﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace Sensor.UI.Converters;

public class BoolToPortStatusText : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return ToValue(value);
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return ToValue(value);
    }
    private  static string ToValue(object value)
    {
        if (value != null && bool.TryParse(value.ToString(), out bool result))
        {
            return result ? "关闭串口" : "打开串口";
        }
        return "未知状态";
    }
}